﻿using System;
using Microsoft.Practices.Unity;

using SharedGenomics.Core.Configuration;

namespace SharedGenomics.Workbench.Core.Configuration
{
    /// <summary>
    /// Configures the container with all 'core' services which are used throughout the workbench. It also configures the container with the event broker
    /// extension which is responsible for wiring up dependencies with the event broker
    /// </summary>
    public class CoreContainerConfigurationStrategy : IContainerConfigurationStrategy
    {
        public void Configure(ContainerConfigurationContext context)
        {
            var container = context.Container;

            container.RegisterInstance<IUnityContainer>(container);
            container.RegisterType<IEventBroker, EventBroker>(new ContainerControlledLifetimeManager());
            container.AddNewExtension<EventBrokerRegistrationContainerExtension>();

            //setup login manager
            container.RegisterType<IAuthenticationService, SharedGenomics.Workbench.Services.UserAuthenticationService>();
            container.RegisterType<ILoginManager, LoginManager>(new ContainerControlledLifetimeManager());
            container.RegisterType<ILoginRequiredGuard, LoginRequiredGuard>(new ContainerControlledLifetimeManager());

            //background executor
            container.RegisterType<IBackgroundExecutor, BackgroundExecutor>();
        }
    }
}
